<?php

namespace App\Http\Controllers\Api;

use App\VolunteerApply;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class IndexController extends Controller
{
    public function joinVolunteerApply(Request $request){
        $realname   =$request->get('realname');
        $sex        =$request->get('sex');
        $id_card    =$request->get('id_card');
        $email      =$request->get('email');
        $phone      =$request->get('phone');
        $province   =$request->get('province');
        $city       =$request->get('city');
        $area       =$request->get('area');
        $description=$request->get('description');
        if (!$realname)
            return response()->json(['level'=>'error','message'=>'请输入您的姓名']);
        if (!$phone)
            return response()->json(['level'=>'error','message'=>'请输入您的联系电话']);

        $volunteerApply             =new VolunteerApply();
        $volunteerApply->realname   =$realname;
        if ($sex)
            $volunteerApply->sex    =$sex;
        if ($id_card)
            $volunteerApply->id_card=$id_card;
        if ($email)
            $volunteerApply->email  =$email;
        $volunteerApply->phone      =$phone;
        if ($province)
            $volunteerApply->province   =$province;
        if ($city)
            $volunteerApply->city       =$city;
        if ($area)
            $volunteerApply->area       =$area;
        if ($description)
            $volunteerApply->description=$description;
        $volunteerApply->save();
        return response()->json(['level'=>'success','message'=>'申请成功！']);
    }
}
